<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button type="primary" icon="download" @click="handleExportXls('gh_finance_contract_audit')">导出</a-button>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          offset="100"
          finished-text="没有更多了"
          @load="onLoadList"
          :immediate-check="false"
        >
          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
          >
            <div>
              <div class="name">客户姓名：{{ item.name || '无' }}</div>
              <div class="contact">
                <span>合同编号：{{ item.contractNo || '无' }}</span>
              </div>
              <div class="contact">
                <span>项目地址：{{ item.address || '无' }}</span>
              </div>
              <div class="contact">
                <span>电话：{{ item.phone || '无' }}</span>
                <span style="margin-left: 20px">经办人：{{ item.createBy || '无' }}</span>
              </div>
              <div class="contact">
                <span>证件号码：{{item.cardNo || '无'}}</span>
                <!--<span style="margin-left: 20px">创建人：{{ item.createBy || '无' }}</span>-->
                <span style="float: right">
                  <a @click.stop="payment(item)" v-if="item.payStatus == 0">收款</a>
                </span>
              </div>
              <div class="contact">
                <span>收款状态：{{ item.payStatus === 0?'待收款':'已收款' || '无' }}</span>
                <span style="margin-left: 20px">收款方式：{{ item.payType === 1?'线上收款':'线下收款' || '无' }}</span>
              </div>
              <div class="contact">
                <span>签订时间：{{ item.decidesTime || '无' }}</span>
                <span style="margin-left: 20px">签订金额：{{ item.money || 0 }}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>

      <!--<a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <a slot="contractNo" @click="contractDetail(record.customerId)" slot-scope="text,record">{{ text }}</a>

        <span slot="collectImg" slot-scope="text,record">
          <a v-if="text != null && text !== ''" @click="downloadFile(text)">预览</a>
          <span v-if="text==null || text === ''">无</span>
        </span>

        <span slot="payImg" slot-scope="text,record">
          <a v-if="text != null && text !== ''" @click="downloadFile(text)">预览</a>
          <span v-if="text==null || text === ''">无</span>
        </span>

        <span slot="action" slot-scope="text, record">
          &lt;!&ndash;<a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />&ndash;&gt;
          <a @click="payment(record)" v-if="record.payStatus == 0">收款</a>
        </span>

      </a-table>-->
    </div>

    <contract-audit-modal ref="contractAuditModal" @ok="modalFormOk"></contract-audit-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import contractAuditModal from './modules/contractAuditModal'
  import { getAction } from "@api/manage";

  export default {
    name: 'contractAuditList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      contractAuditModal
    },
    data () {
      return {
        description: '合同待收款管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'合同编号',
            align:"center",
            dataIndex: 'contractNo',
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'contractNo' },
          },
          {
            title:'客户姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'项目地址',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'证件号码',
            align:"center",
            dataIndex: 'cardNo'
          },
          {
            title:'签订时间',
            align:"center",
            dataIndex: 'decidesTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'签订金额',
            align:"center",
            dataIndex: 'money'
          },
          {
            title:'付款凭证',
            align:"center",
            dataIndex: 'payImg',
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'payImg' },
          },
          {
            title:'收款状态',
            align:"center",
            dataIndex: 'payStatus',
            customRender:function (text) {
              if(text === 0) {
                return "待收款"
              } else {
                return "已收款"
              }
            }
          },
          {
            title:'收款方式',
            align:"center",
            dataIndex: 'payType',
            customRender:function (text) {
              if(text === 1) {
                return "线上收款"
              } else if (text === 2){
                return "线下收款"
              }
            }
          },
          {
            title:'收款凭证',
            align:"center",
            dataIndex: 'collectImg',
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'collectImg' },
          },
          {
            title:'经办人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ghFinanceContractAudit/list",
          delete: "/ghFinanceContractAudit/delete",
          deleteBatch: "/ghFinanceContractAudit/deleteBatch",
          exportXlsUrl: "/ghFinanceContractAudit/exportXls",
          importExcelUrl: "ghFinanceContractAudit/importExcel",
          queryCustomerContractFile: "/ghCustomerFileInfo/queryByCustomerId",
        },
        dictOptions:{},
        superFieldList:[],
        contractFile:{},
        finished: false,
      }
    },
    created() {

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      onLoadList(e){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = []
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      payment(record){
        this.$refs.contractAuditModal.edit(record);
      },
      //预览付款凭证
      downloadFile(value){
        window.open(value)
      },
      //查看意向购买合同
      contractDetail(customerId){
        getAction(this.url.queryCustomerContractFile,{customerId:customerId,contractType:1}).then((res) => {
          if (res.success) {
            this.contractFile = res.result;
            window.open(this.contractFile.fileUrl);
          }else {
            this.$message.error("该合同不存在!")
          }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  /deep/ .van-dropdown-menu__bar{
    height: 30px;
    box-shadow: none;
    border: 1px solid lightgrey;
    border-radius: 5px;
  }

  .list{
    overflow-y: scroll;
    height:100vh;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list {
    align-items: center;
    border-top: 1px solid #d9d9d9;
    /*height: 120px;*/
  }
  .name{
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #161616;
    line-height: normal;
  }
  .contact{
    font-size: 12px;
    color: #a39f9f;
    margin-bottom: 5px;
  }
</style>